#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
const int N=1e7+50;
int p[N];
string s;
int Manacher(string s){
    memset(p,0,sizeof(p));
    int sl=s.size();
    string t="$#";
    for(int i=0;i<sl;i++){
        t+=s[i];
        t+="#";
    }
    int tl=t.size();
    int id=0;
    int mx=0;
    int resLen=0;
    int resCenter=0;
    for(int i=1;i<tl;i++){
        p[i]=mx>i?min(p[2*id-i],mx-i):1;
        while(t[i+p[i]]==t[i-p[i]]){
            p[i]++;
        }
        if(mx<i+p[i]){
            mx=i+p[i];
            id=i;
        }
        if(resLen<p[i]){
            resLen=p[i];
            resCenter=i;
        }
    }
    return resLen-1;
}
int main(void){
    int n;
    scanf("%d",&n);
    while(n--){
        cin >> s;
        cout << Manacher(s) << endl;
    }
    return 0;
}